home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mcomm557.zip / SMALTERM.C < prev    next >
C/C++ Source or Header  |  1993-09-11  |  37KB  |  1,079 lines

  1.  
  2. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. *      S M A L T E R M  --  D e m o   D r i v e r   f o r   M C o m m 5     *
  4. *                          A s y n c   R o u t i n e s                      *
  5. *                                                                           *
  6. *              Mike Dumdei, 6 Holly Lane, Texarkana TX 75503                *
  7. *                  North East Texas DataLink, 903 838-6713                  *
  8. *                                                                           *
  9. *               (Link with comm_s.lib for external functions)               *
  10. *               cl smalterm.c /link comm_s          (Microsoft C)           *
  11. *               tcc smalterm.c comm_s.lib           (Turbo C)               *
  12. *               ztc -b smalterm.c comm_s.lib        (Zortech C)             *
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #if !defined(__TURBOC__)
  17.     #include <sys\types.h>
  18. #endif
  19. #include <sys\stat.h>
  20. #include <io.h>
  21. #include <stdlib.h>
  22. #include <conio.h>
  23. #include <ctype.h>
  24. #include <string.h>
  25. #include <process.h>
  26. #include <stdarg.h>
  27. #if defined(__ZTC__)
  28.   #define   MSDOS           1
  29.   #define   stricmp         strcmpl
  30. #endif
  31. #include <dos.h>
  32. #include <bios.h>
  33.  
  34. #include "comm.h"                            /* header for async functions */
  35. #include "ansidrv.h"                   /* header for ANSI display routines */
  36. #define KEY_INT
  37. #include "keys.h"                                 /* key definition header */
  38. #if defined(RED)
  39.     #undef RED
  40. #endif
  41. #include "colors.h"                  /* vid mode & color definition header */
  42. #include "extra.h"                               /* extra functions header */
  43.  
  44. #if defined (__TURBOC__)                                        /* Turbo C */
  45.   #define   NO_FILES(x)     findfirst((x), &findbuf, 0)
  46.   #define   find_t          ffblk
  47.   #define   KBHIT           bioskey(1)
  48.   #define   KBREAD          bioskey(0)
  49.   #include  <dir.h>
  50. #else                                            /* Microsoft C, Zortech C */
  51.   #include  <direct.h>
  52.   #define   NO_FILES(x)     _dos_findfirst((x), _A_NORMAL, &findbuf)
  53.   #define   KBHIT           _bios_keybrd(_KEYBRD_READY)
  54.   #define   KBREAD          _bios_keybrd(_KEYBRD_READ)
  55. #endif
  56.  
  57. #define POP         0
  58. #define PUSH        1              /* used in screen save/restore function */
  59. #define RXBUFSZ     4096                            /* rx ring buffer size */
  60. #define TXBUFSZ     1050                            /* tx ring buffer size */
  61. #define LOST_CARRIER -1
  62. #define NO_INPUT     -1
  63. #define ESC_PRESSED  -2
  64. #define TIMED_OUT    -3
  65.  
  66. #define TRUE          1
  67. #define FALSE         0
  68. #define REG     register
  69.  
  70. typedef unsigned char uchar;
  71. typedef unsigned long ulong;
  72. typedef unsigned int uint;
  73.  
  74.  
  75. /*      f u n c t i o n   d e c l a r a t i o n s     */
  76. extern int main(int argc,char * *argv);
  77. static int proc_keypress(int ch);
  78. static int proc_rxch(int ch);
  79. static int proc_fkey(int keycd);
  80. static int watch_cd(void );
  81. static int rcls(void);
  82. static int toggle_log(void );
  83. static int toggle_echo(void );
  84. static int toggle_lfs(void );
  85. static int toggle_dtr(void );
  86. static int dial_nbr(void );
  87. static int shell_to_dos(void );
  88. static int host_mode(void );
  89. static int shell_remote(void );
  90. static int run_batch(int keycd);
  91. static int exit_term(void );
  92. static int do_help(void );
  93. static int async_tx_str(char *str);
  94. static int async_tx_echo(char *str);
  95. static int screen_pushpop(int flag);
  96. static int chg_parms(void );
  97. static int rx_timeout(int Tenths);
  98. static int waitfor(char *str, int ticks);
  99. static int waitforOK(int ticks );
  100. static int prompt(char *kbuf,char *promptmsg,int maxchars);
  101. static int comprompt(char *kbuf,char *promptmsg,int maxchars);
  102. static int hang_up(void );
  103.  
  104. /*      g l o b a l   v a r i a b l e s     */
  105.  
  106. ASYNC   *port;                               /* pointer to async structure */
  107.  /* default to COM1 */
  108. char    com_str[5] = "COM1";           /* text for port ("COM1" or "COM2") */
  109. int     IOadrs = 0x3f8;                      /* comm port base I/O address */
  110. char    irqm = IRQ4;                         /* mask for selected IRQ line */
  111. char    vctrn = VCTR4;                        /* comm interrupt vector nbr */
  112.  
  113. FILE    *logfil = NULL;                                 /* log file handle */
  114. char    dialstr[40];                           /* dial string storage area */
  115. int     ChkgKbd = 1;              /* watch for ESC during rcv with timeout */
  116. int     ChkgCarrier = 0;        /* monitor carrier during rcv with timeout */
  117. char    buf[200];                                    /* gen purpose buffer */
  118. int     lfs = 0, echo = 0, dtr = 1, autoans = 0;          /* various flags */
  119. struct find_t findbuf;                        /* struct for NO_FILES macro */
  120. int     cyn, hred, grn, hgrn, wht, hblu;           /* text color variables */
  121. int     hostcnt = 0;                        /* toggle to host mode counter */
  122.  
  123. /*
  124.             * * * *    M A I N    * * * *
  125. */
  126. main(int argc, char **argv)
  127. {
  128.     static char params[10] = "1200N81";              /* default parameters */
  129.     char        buf[100];
  130.     int         got_port = FALSE;
  131.     unsigned    i, ch;
  132.  
  133.     initvid();                                /* initialize video routines */
  134.     if (v_mode == CO80)
  135.     {
  136.         cyn = CYN, hred = H_RED, grn = GRN, hgrn = H_GRN,
  137.         wht = WHT, hblu = H_BLU;
  138.     }
  139.     else
  140.     {
  141.         cyn = WHT, hred = H_WHT, grn = WHT, hgrn = H_WHT,
  142.         wht = WHT, hblu = H_WHT;
  143.     }
  144.     v_color = cyn;
  145.     cls();                                             /* clear the screen */
  146.  
  147.     /*  D I S P L A Y   S I G N O N  */
  148.     v_color = hred;
  149.     d_str("SMALTERM - Sample driver for MCOMM5 comm routines\n");
  150.     v_color = grn;
  151.     d_str("    Mike Dumdei, 6 Holly Lane, Texarkana TX 75503\n");
  152.     d_str("    North East Texas DataLink   903 838-6713\n");
  153.     v_color = hred;
  154.     d_str("Usage: smalterm {COM1 | COM2} {param str EX: 2400N81}\n\n");
  155.     v_color = cyn;
  156.  
  157.     /*  P R O C E S S   C O M M A N D   L I N E   A R G S  */
  158.     for (i = 1; i < 3; i++)        /* do it twice so args can be any order */
  159.     {                              /*  or have one arg and not the other   */
  160.         if (argc > i)
  161.         {
  162.             if (!got_port && !stricmp(argv[i], "COM1"))
  163.                 got_port = TRUE;
  164.             else if (!got_port && !stricmp(argv[i], "COM2"))
  165.             {
  166.                 got_port = TRUE, strcpy(com_str, "COM2");
  167.                 IOadrs = 0x2f8, irqm = IRQ3, vctrn = VCTR3;
  168.             }
  169.             else if (strlen(argv[i]) < 9)   /* assume a valid param string */
  170.                 strcpy(params, argv[i]);
  171.         }
  172.     }
  173.  
  174.     /*  O P E N   T H E   C O M M   P O R T  */
  175.     port = malloc(sizeof(ASYNC));
  176.     AllocRingBuffer(port, RXBUFSZ, TXBUFSZ, 1);    /* alloc FAR ring bufrs */
  177.     if ((ch = async_open(port, IOadrs, irqm, vctrn, params)) != 0)
  178.     {
  179.         /* couldn't open the port code */
  180.         strsum(buf, "SMALTERM: Couldn't open ", com_str, " using ",
  181.               params, " for parameters -- ABORTING\n\n", NULL);
  182.         d_str(buf);
  183.         strsum(buf, "Error code = ", itoa(ch, &buf[50], 10), "\n\n", NULL);
  184.         d_str(buf);
  185.         exit(ch);
  186.     }
  187.  
  188.     /* opened OK code */
  189.  
  190.     d_str(strsum(buf, "SMALTERM: ", com_str, " -- PORT OPENED\n\n", NULL));
  191.     d_str("Press F1 for HELP screen\n");           /* tell how to get help */
  192.     /* display status line */
  193.     SETWND(0, 0, 23, 79);                           /* set the window size */
  194.     d_strnat(24, 0, '═', cyn, 80);                          /* paint a bar */
  195.     d_msgat(24, 60, hgrn, strupr(com_str));                /* display port */
  196.     d_msgat(24, 65, hgrn, strupr(params));               /* display params */
  197.     d_msgat(24, 10, hgrn, "DTR");                           /* DTR is high */
  198.     *dialstr = '\0';                              /* clear out dial string */
  199.     tickhookset(1);        /* enable 'ticker' variable for timer func